package com.example.controller;

import com.example.domain.Message;
import com.example.service.SseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.util.UUID;

@RestController
@Slf4j
@RequestMapping("/sse")
public class SseController {
    private SseService sseService;
    public SseController(SseService sseService) {
        this.sseService = sseService;
    }
    @GetMapping(value = "/connect",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter createConnection(){
        String uuid = UUID.randomUUID().toString();
        log.info("新用户连接:{}",uuid);
        return sseService.connect(uuid);
    }
}
